<template>
  <div class="h-100">
    <div class="add-btn" @click="showAdd = true">
      新增
    </div>
    <el-table
      key="list"
      :data="list1"
      style="width: 1250px;margin-bottom: 20px;"
      height="633"
      border
      stripe
      :header-cell-style="{
        textAlign: 'center',
      }"
      :cell-style="{
        textAlign: 'center',
      }"
    >
      <el-table-column label="一级产业集群字典">
        <template slot-scope="scope">
          <div v-if="scope.row.cate == '一级产业'">
            {{ scope.row.name }}
          </div>
          <div v-else>
            ---
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="二级产业名称字典">
        <template slot-scope="scope">
          <div v-if="scope.row.cate == '二级产业'">
            {{ scope.row.name }}
          </div>
          <div v-else>
            ---
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="240">
        <template slot-scope="scope">
          <span :class="scope.row.statu == 1 ? 'status' : 'status-not'">{{
            scope.row.statu == 1 ? "启用" : "禁用"
          }}</span>
          <el-switch
            v-model="scope.row.statu"
            active-color="#35BF69"
            @change="fieldStatus($event, scope.row.id)"
            :active-value="1"
            :inactive-value="2"
          ></el-switch>
          <span
            class="edit-btn"
            @click="setEditID(scope.row.id, scope.row.name)"
            >编辑</span
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="新增产业字典" :visible.sync="showAdd" @close="closeAdd">
      <div class="add-bm">
        <p>
          <span>字典名称：</span>
          <el-input v-model="admin" placeholder="请输入"></el-input>
        </p>
        <p>
          <span>显示级别：</span>
          <el-input v-model="level" placeholder="请输入"></el-input>
        </p>
        <p>
          <span>上级产业：</span>
          <el-select placeholder="请选择" v-model="industry">
            <el-option
              v-for="(item, index) in industryArr"
              :key="index"
              :label="item.name"
              :value="item.industry_id"
            ></el-option>
          </el-select>
        </p>
      </div>
      <div slot="footer" class="dialog-footer">
        <div class="qx" @click="closeAdd">
          取消
        </div>
        <div class="qd" @click="closeAdd">
          确 定
        </div>
      </div>
    </el-dialog>
    <el-dialog
      title="修改产业字典"
      class="edit-dialog"
      :visible.sync="showEdit"
      @close="closeEdit"
    >
      <div class="add-bm">
        <p>
          <span>导航名称：</span>
          <el-input v-model="mulu1"></el-input>
        </p>
      </div>

      <div slot="footer" class="dialog-footer">
        <div class="qx" @click="closeEdit">
          取消
        </div>
        <div class="qd" @click="modifyFields">
          确 定
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listField, fieldStatu, modifyFields } from "@/api/system";
export default {
  data() {
    return {
      mulu1: "",
      editId: "",
      showEdit: false,
      showAdd: false,
      admin: "",
      level: "",
      industry: "",
      industryArr: [],
      list1: [],
    };
  },
  mounted() {
    this.listField();
  },
  methods: {
    closeAdd() {
      this.admin = "";
      this.level = "";
      this.industry = "";
      this.showAdd = false;
    },
    closeEdit() {
      this.mulu1 = "";
      this.editId = "";
      this.showEdit = false;
    },
    setEditID(id, name) {
      this.mulu1 = name;
      this.editId = id;
      this.showEdit = true;
    },
    // 修改行业名称
    async modifyFields() {
      const res = await modifyFields({
        id: this.editId,
        newname: this.mulu1,
      });
      if (res.code == 0) {
        this.$message({
          message: res.msg,
          type: "success",
        });
        this.closeEdit();
        // this.getorgStaff();
      } else {
        this.$message({
          message: res.msg,
          type: "error",
        });
      }
      this.listField();
    },
    // 获取数据列表
    async listField() {
      const res = await listField({});
      this.list1 = res;
    },
    // 更改行业状态
    async fieldStatus(e, a) {
      if (e == 1) {
        this.statu = 2;
      } else {
        this.statu = 1;
      }
      const res = await fieldStatu({
        id: a,
        statu: this.statu,
      });
      if (res.code == 0) {
        // this.listField();
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import "./table.less";
.h-100 {
  height: 100%;
  text-align: left;
  overflow: hidden;
}
.add-btn {
  width: 120px;
  height: 38px;
  line-height: 38px;
  background: #f89718;
  border-radius: 4px;
  font-size: 16px;
  color: #ffffff;
  cursor: default;
  text-align: center;
}

/deep/ .el-dialog {
  padding: 0 46px;
  width: 720px !important;
  height: 520px !important;
  top: 50%;
  margin-top: -260px !important;
  box-shadow: 0px 5px 50px 0px rgba(186, 186, 186, 0.5);
  border-radius: 20px;
}
/deep/.edit-dialog .el-dialog {
  padding: 0 46px;
  width: 720px !important;
  height: 400px !important;
  top: 50%;
  margin-top: -200px !important;
}
.add-bm {
  padding: 20px 50px;
  p {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    height: 54px;
    line-height: 54px;
    span {
      font-size: 18px;
      color: #333333;
    }
  }
  /deep/ .el-input,
  /deep/ .el-input__inner {
    width: 350px;
    height: 54px;
    background: #f7f7f7;
    border-radius: 8px;
    border: 0;
    font-size: 18px;
    color: #333333;
  }
}

/deep/ .el-dialog__header {
  padding-top: 30px;
  height: 100px;
  line-height: 70px;
  border-bottom: 1px dashed #ddd;
  text-align: center;

  .el-dialog__title {
    font-size: 30px;
    font-weight: bold;
    color: #446db3;
  }
}

/deep/.el-dialog__body {
  padding: 30px 20px;
  .tips {
    font-size: 24px;
  }
  li {
    margin: 0 auto;
    // span {
    //   width: 80px !important;
    //   padding: 0 !important;
    //   font-size: 18px;
    //   color: #333333;
    // }
    .el-input__inner {
      width: 350px;
      height: 54px;
      background: #f7f7f7 !important;
      border-radius: 8px;
      border: none !important;
    }
  }
}
/deep/.dialog-footer {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-evenly;
  .qx {
    display: inline-block;
    width: 247px;
    height: 48px;
    line-height: 44px;
    border: 2px solid #446db3;
    border-radius: 10px;
    font-size: 26px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #446db3;
    text-align: center;
    cursor: default;
  }
  .qd {
    display: inline-block;
    width: 247px;
    height: 48px;
    line-height: 44px;
    background: #446db3;
    box-shadow: 0px 2px 5px 0px rgba(68, 109, 179, 0.5);
    border: 2px solid #446db3;
    border-radius: 10px;
    font-size: 26px;
    font-weight: bold;
    color: #ffffff;
    text-align: center;
    cursor: default;
  }
}
/deep/ .el-icon-close:before {
  content: "";
  display: block;
  width: 21px;
  height: 20px;
  background: url("~@img/system/icon-close.png");
}
/deep/.el-dialog__headerbtn {
  right: 50px;
}
/deep/ .el-table__header-wrapper {
  margin-bottom: 4px;
}
/deep/ .el-table::before,
/deep/ .el-table::after {
  width: 0 !important;
}
/deep/ .el-table--border::after,
/deep/ .el-table--group::after {
  width: 0 !important;
}
/deep/ .el-table__row td:last-of-type {
  border-right: 4px solid #fff !important;
}
/deep/ .el-table--scrollable-y .el-table__body-wrapper {
  padding-bottom: 20px;
}
.status {
  margin-right: 10px;
  font-size: 14px;
  font-weight: bold;
  color: #333333;
  cursor: default;
}
.status-not {
  margin-right: 10px;
  font-size: 14px;
  font-weight: bold;
  color: #f15847;
  cursor: default;
}
.edit-btn {
  display: inline-block;
  margin-left: 20px;
  width: 50px;
  height: 24px;
  line-height: 24px;
  background: #5889dc;
  border-radius: 4px;
  font-size: 14px;
  color: #ffffff;
  cursor: default;
}

/*
  *常用电脑尺寸  1680 * 900
  *              1536 * 864
  *              1440 * 900
  *ipad pro      1366 * 1024
  *ipad mini     1024 * 768
  *ipad          1024 * 768
 */
/*分辨率低于1680，采用下面的样式*/
@media screen and (max-device-width: 1680px) {
  /deep/.el-table {
    height: 530px !important;
  }
}
/*分辨率低于1536，采用下面的样式*/
@media screen and (max-device-width: 1536px) {
  /deep/.el-table {
    height: 484px !important;
  }
}
/*分辨率低于1440，采用下面的样式*/
@media screen and (max-device-width: 1440px) {
  /deep/.el-table {
    height: 530px !important;
  }
}
/*分辨率低于1366，采用下面的样式*/
@media screen and (max-device-width: 1366px) {
  /deep/.el-table {
    height: 626px !important;
  }
}
/*分辨率低于1180，采用下面的样式*/
@media screen and (max-device-width: 1180px) {
  /deep/.el-table {
    height: 480px !important;
  }
}
/*分辨率低于1024，采用下面的样式*/
@media screen and (max-device-width: 1024px) {
  /deep/.el-table {
    height: 436px !important;
  }
}
</style>
